import { useState, useCallback } from "react";

export const useObjectState = <T>(
  initState: T
): [T, (newObject: Partial<T>) => void] => {
  const [state, setState] = useState(initState);

  const updateValue = useCallback(
    (newObject: Partial<T>) => {
      setState((prev) => ({ ...prev, ...newObject }));
    },
    [setState]
  );

  return [state, updateValue];
};
